import comTitle from "@/views/com/com_title.vue";
import buyingIfor from "./buyingIfor/buyingIfor.vue";
import returnInfo from "./returnInfo/returnInfo.vue";
import choiceShop from "./choiceShop.vue";
import cropperModal from "@/components/cropper/index.vue";
import { shopInstockDetail } from '@/api/shop/stock/instock.js'

export default {
    components: {
        comTitle,
        buyingIfor,
        choiceShop,
        cropperModal,
        returnInfo
    },
    data() {
        return {
            labelWidth: "150px",
            disabled: false,
            ruleForm: {

            },
            info: {
                // order: "PO0012006020002",
                // chuku: "苏州运营中心总仓",
                // ruku: "采购入库",
                // dh: "15314226666",
                // sj: '2016-07-06',
                // lxr: "小王",
                // ckdz: "江苏省苏州市姑苏区平江街道东环路1673号东林里小区"
            },
            rules: {
                gysmc: [
                    { required: true, },
                ],
                date1: [
                    { required: true },
                ],
                lx: [
                    { required: true },
                ]
            },
            gysmc: [                //供应商名称
                {
                    label: "供应商A",
                    value: '供应商A'
                },
                {
                    label: "供应商B",
                    value: '供应商B'
                }
            ],
            mendianList: [  //门店list

            ],

            imageUrl: "",
            loading: false,  //上传
            optionsData: {
                title: "商品图片",     //弹框表头
                img: '',   //裁切图片地址
                autoCrop: true, //是否默认生成截图框
                autoCropWidth: 200, //默认生成截图框宽度
                autoCropHeight: 200, //默认生成截图框高度
                fixedBox: true //固定截图框大小 不允许改变
            },
            number: 0,
            fileList: [],
            fileListUrl: [], //放大展示


            status: true,  //待入库和完成详情
        }
    },
    watch: {
        '$route'() {
            this.getList(this.$route.query.inStockId)
            // this.status = (this.$route.query.status=='02')   //是否是入库完成还是待入库状态
        }
    },
    mounted() {
        this.getList(this.$route.query.inStockId)
        // this.status = (this.$route.query.status =='02')   //是否是入库完成还是待入库状态
    },
    methods: {
        getList(inStockId) {
            shopInstockDetail(inStockId).then(val => {
                this.info = val.data
                if (this.info.inStockStatus == '00') {
                    this.info.inStockStatusH = '待入库'
                }
                if (this.info.inStockStatus == '01') {
                    this.info.inStockStatusH = '部分入库'
                }
                if (this.info.inStockStatus == '02') {
                    this.info.inStockStatusH = '已完成'
                }
                //00待出库 01部分出库 02已出库  03作废 04已完成
                if (this.info.outStockStatus == '00') {
                    this.info.outStockStatusH = '待出库'
                }
                if (this.info.outStockStatus == '01') {
                    this.info.outStockStatusH = '部分出库'
                }
                if (this.info.outStockStatus == '02') {
                    this.info.outStockStatusH = '已出库'
                }
                if (this.info.outStockStatus == '03') {
                    this.info.outStockStatusH = '作废'
                }
                if (this.info.outStockStatus == '04') {
                    this.info.outStockStatusH = '已完成'
                }
                this.info.goods.forEach(ele=>{
                    ele.daiqueren = ele.inNum-ele.confirmInNum
                })
                this.trigger(this.info.goods)
            })
        },
        submitSave() {   //提交并保存
            console.log(this.ruleForm)
            this.$refs['ruleForm'].validate((valid) => {
                if (valid) {
                    alert('submit!');
                } else {
                    console.log('error submit!!');
                    return false;
                }
            });
        },
        quxiao(ruleForm) {  //取消
            this.$router.go(-1)
            this.$refs[ruleForm].resetFields();
            this.ruleForm = {

            }
        },
        addStore() {
            this.$refs.choiceShop.dialogVisibleTile = '添加直送门店'
            this.$refs.choiceShop.dialogVisible = true
        },
        trigger(data) {
            this.$refs.buyingIfor.dataList = []
            this.$refs.buyingIfor.dataList.push({   //将门店push 到采购信息中去
                loadData: data
            })
            this.$refs.buyingIfor.total.number = data.length
        },
        pslxChange(e) {           //总仓还是门店
            this.$refs.buyingIfor.dataList = []
            if (e.target.value == 1) {
                this.$refs.buyingIfor.dataList.push({ loadData: [{}] })
            } else {
                this.$refs.buyingIfor.dataList = []
            }
        },
        cxsjChange(e) {
            var timeList = [this.formDate(e[0]._d), this.formDate(e[1]._d)]
            this.ruleForm.startCxsj = timeList[0]
            this.ruleForm.endCxsj = timeList[1]
        },
        handleChange(info) {  //上传触发
            let { options } = this;
            console.log(info)
            fileBase64(info.file.originFileObj).then(result => {
                let target = Object.assign({}, options, {
                    img: result.result,
                    files: result.files
                })
                this.$refs['cropperModal'].edit(target);
            })
        },
        beforeUpload(file) {
            const isJpgOrPng = file.type === 'image/jpeg' || file.type === 'image/png';
            if (!isJpgOrPng) {
                this.$message.error('图片格式不支持！');
            }
            const isLt1M = file.size / 1024 / 1024 < 1;
            if (!isLt1M) {
                this.$message.error('图片大小限制在1MB内!');
            }
            return isJpgOrPng && isLt1M;
        },
        setZhutu() {

        },
        delUplod(file) {
            const index = this.fileList.indexOf(file)
            const newFileList = this.fileList.slice()
            newFileList.splice(index, 1)
            this.fileList = newFileList
        },
        handleCropperSuccess(data) {  //图片裁切完成保存
            fileBase64(data).then(result => {
                this.imageUrl = result.result
                this.fileListUrl.push(this.imageUrl)
                this.fileList.push({
                    uid: this.number++,
                    name: 'image.png',
                    status: 'done',
                    url: this.imageUrl
                })
            })
        },
    },

} 